﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Text;
using Common;

public partial class website_admin_members_shippingaddresseditor : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin();

        switch (RequestBase.GetFormString("otype"))
        {
            case "getregionlist":
                LoadingRegionList();
                break;
            case "getaddressobj":
                InitializeAddressObj();
                break;
        }
    }

    #region 获取三级地区级联目录数据
    /// <summary>
    /// 获取三级地区级联目录数据
    /// </summary>
    void LoadingRegionList()
    {
        string parentid = RequestBase.GetFormString("parentid");
        StringBuilder selOptions = new StringBuilder();
        string items = "<option value=\"{0}\">{1}</option>";

        string layer = RequestBase.GetFormString("layer");
        switch (layer)
        {
            case "1":
                selOptions.Append(string.Format(items, "", "-- 请选择省份 --"));
                break;
            case "2":
                selOptions.Append(string.Format(items, "", "-- 请选择城市 --"));
                break;
            case "3":
                selOptions.Append(string.Format(items, "", "-- 请选择区县 --"));
                break;
        }

        DataTable dat = BLL.CommonBLL.Select(
            "RegionBase",
            "RegionName, RegionId",
            " AND DeletionStateCode = 0 AND ParentId = " + parentid + " AND Layer=" + layer + " ORDER BY RegionName ASC");

        foreach (DataRow dr in dat.Select(""))
        {
            selOptions.Append(string.Format(items, dr["RegionId"].ToString(), dr["RegionName"].ToString()));
        }

        dat.Clear();
        dat.Dispose();
        BLL.AjaxHelper.ResponseWrite(selOptions.ToString());
    }
    #endregion

    #region 送货地址处理方法 
    /// <summary>
    /// 获取送货地址信息
    /// </summary>
    void InitializeAddressObj()
    {
        Model.ShippingAddressBase _obj = BLL.ShippingAddressBase.GetObjectById(RequestBase.GetFormString("txtShippingAddressId"));
        StringBuilder GetValues = new StringBuilder();
        GetValues.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?><ShippingAddressBase><fileds>");
        GetValues.Append("<filed name=\"ShipAddressName\">" + _obj.ShipAddressName + "</filed>");
        GetValues.Append("<filed name=\"ShipAddress\">" + _obj.ShipAddress + "</filed>");
        GetValues.Append("<filed name=\"ShipCounties\">" + _obj.ShipState + " | " + _obj.ShipCity + " | " + _obj.ShipCounties + "</filed>");
        GetValues.Append("<filed name=\"ShipZip\">" + _obj.ShipZip + "</filed>");
        GetValues.Append("<filed name=\"ShipTel\">" + _obj.ShipTel + "</filed>");
        GetValues.Append("<filed name=\"ShipMobile\">" + _obj.ShipMobile + "</filed>");
        GetValues.Append("<filed name=\"ShipToName\">" + _obj.ShipToName + "</filed>");
        GetValues.Append("<filed name=\"CountieId\">" + _obj.ShipCountiesId.ToString() + "</filed>");
        GetValues.Append("<filed name=\"CityId\">" + _obj.ShipCityId.ToString() + "</filed>");
        GetValues.Append("<filed name=\"ProvinceId\">" + _obj.ShipStateId.ToString() + "</filed>");
        GetValues.Append("<filed name=\"ShipCountryId\">" + _obj.ShipCountryId.ToString() + "</filed>");
        GetValues.Append("</fileds></ShippingAddressBase>");

        BLL.AjaxHelper.ResponseWriteXML(GetValues.ToString());
    }  
    #endregion 
}
